package com.mali.common.dto;

import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data){
        return new Result<>(HttpStatus.HTTP_OK, "请求成功", data);
    }

    public static <T> Result<T> success(String message, T data){
        return new Result<>(HttpStatus.HTTP_OK, message, data);
    }

    public static <T> Result<T> fail(String message){
        return new Result<>(HttpStatus.HTTP_INTERNAL_ERROR, message, null);
    }

    public static <T> Result<T> fail(Integer code, String message){
        return new Result<>(code, message, null);
    }

    public boolean success(){
        return this.code == HttpStatus.HTTP_OK;
    }

}
